// 暗黑模式切换
import { defineStore } from "pinia";
export const useDarkModeStore = defineStore("darkMode", {
  state: () => {
    return {
      darkMode: false,
      color: "",
    };
  },
  actions: {
    // 切换暗黑主题
    changeDarkMode() {
      // 获取HTML根节点
      const html = document.documentElement;
      html.classList.toggle("dark");
      this.darkMode = html.classList.contains("dark");
    },
    // 自定义主题
    changeColor(color: any) {
      // 获取HTML根节点
      const html = document.documentElement;
      html.style.setProperty("--el-color-primary", color);
      this.color = color;
    },
  },
  persist: true, // 启用持久化
});
